home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Watch Volume Mount / MountVol init.c < prev    next >
C/C++ Source or Header  |  1993-11-22  |  2KB  |  51 lines

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *                        Messing around Mac System software
  5.  *            This is a code resource - patch to the MounVol system trap
  6.  *
  7.  * The purpose of the patch is to intercept and save the drive ref number,
  8.  * which is passed as a parameter to the _MountVol system trap (PBMountVol from C).
  9.  * The saved device ref number can be retrieved by whoever is interested. The
  10.  * trick is the ref number is saved within the fixed offset from the entry point
  11.  * to this trap patch.
  12.  *
  13.  * Note! This is a code resource which is supposed to be installed as a
  14.  * trap-handler. Don't do anything stupid here! Don't call the ToolBox!
  15.  * The code must be position-independent. Nobody sets up registers to address
  16.  * the global variables: either use A4 addressing (but fon't forget to set
  17.  * up the A4 at the outset), or put the variables in the CODE segment and access
  18.  * them through PC (which is only one register which is for sure set up
  19.  * right).
  20.  *
  21.  * Interfaces
  22.  * a0 contains the ptr to the parameter block
  23.  *        +22(a0) word  contains the drive ref number for the volume to mount
  24.  * The standard _MountVol trap routine is entered after the drive ref number
  25.  * is saved.
  26.  *
  27.  ***********************************************************************
  28.  */
  29.  
  30. #define Signature 23547
  31.  
  32. long main(void)
  33. {
  34.     asm {
  35.         bra @3                        // Jump around our data
  36.             dc.w    Signature
  37.         @1    dc.w    0                // driver ref number storage
  38.         @2    dc.l    0                // Ptr to the real trap program
  39.         @3
  40.             move.l    a1,-(sp)
  41.             lea        @1,a1
  42.             move.w    22(a0),(a1)        // save the drive ref number
  43.             move.l    (sp)+,a1
  44.         @4    move.l    @2,-(sp)        // Push the address of the real MountVol routine
  45.                                     // to the stack. RTS instruction that terminates
  46.                                     // main() would then pass the control to the
  47.                                     // real handler
  48.     }
  49. }                                    // Note, RTS is to be generated here. We count on it!
  50.  
  51.